home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / lib / mntlib44.zoo / mntlib / dup2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-01  |  777 b   |  38 lines

  1. /* from Dale Schumacher's dLibs library */
  2.  
  3. /* will have to be adjusted at some time ++jrb */
  4. /* use with caution, TOS 1.4 still has double re-direction bug! */
  5.  
  6. #include <stddef.h>
  7. #include <fcntl.h>
  8. #include <errno.h>
  9. #include <mintbind.h>
  10. #include <unistd.h>
  11. #include "lib.h"
  12.  
  13. extern int __mint;
  14.  
  15. int
  16. dup2(handle1, handle2)
  17.     int handle1, handle2;
  18. {
  19.     int rv;
  20.     long flags;
  21.  
  22.     if (handle1 == handle2)
  23.         return (handle2);
  24.  
  25.     if ((rv = (int)Fforce(handle2, handle1)) < 0)
  26.         errno = -rv;
  27.     else {
  28.         if (__OPEN_INDEX(handle2) < __NHANDLES)
  29.             __open_stat[__OPEN_INDEX(handle2)] =
  30.                 __open_stat[__OPEN_INDEX(handle1)];
  31.         if (__mint) {
  32.             flags = (long)Fcntl(handle2, (long)0, F_GETFD);
  33.             (void)Fcntl(handle2, flags & ~FD_CLOEXEC, F_SETFD);
  34.         }
  35.     }
  36.     return (rv < 0) ? -1 : handle2;
  37. }
  38.